package com.example.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

//import com.isdm.sys.util.StringUtil;



public class SimpleExcelUtil {
	/**
	 * 简单excel导出方法,网页下载excel
	 * @param response response对象,用来获取输出流
	 * @param fileName 文件名,如果为空,默认为日期
	 * @param contentList 内容集合,根据每个元素的key与表头集合的key匹配,相同则在同一列
	 * */
	public static void simpleDownLoadExcel(HttpServletResponse response,
			String fileName,
			List<Map<String,Object>> contentList,
			LinkedHashMap<String, String> columnNameMap) throws Exception{
		response.setContentType("application/ms-excel; charset=UTF-8");//传输类型
		if(StringUtil.isEmpty(fileName)){
			fileName="";
		}
		String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());//日期
		response.addHeader("Content-Disposition","attachment;filename=" +fileName+"_"+date + ".xlsx");
		List<List<Map<String, Object>>> contentLists = new ArrayList<List<Map<String,Object>>>();//要导出的内容
		contentLists.add(contentList);
		List<LinkedHashMap<String, String>> columnNameMapLists = new LinkedList<LinkedHashMap<String, String>>();
		columnNameMapLists.add(columnNameMap);
		ExcelUtil.exportExcelForHugeData(response.getOutputStream(), null, null, columnNameMapLists,contentLists);
	}
}
